import { createSlice, PayloadAction, createAsyncThunk } from '@reduxjs/toolkit'

let initialState = {
  token: '',
  loading: false
}

const counterSlice = createSlice({
  name: 'counter',
  initialState,
  reducers: {
    setToken: (state, { payload}) => {
      state.token = payload
    },
    setLoading: (state, { payload }) => {
      state.loading = payload
    }
  },
})

export const { setToken, setLoading } = counterSlice.actions;

// 异步方法
// export const increAsync = (payload:number = 0): AppThunk => async (dispatch, getState) => {
//   const { app: { count } } = getState();
//   dispatch(setLoading(true))
//   setTimeout(() => {
//     dispatch(increment(payload + 5));
//     dispatch(setLoading(false))
//   }, 1000);
// };

export default counterSlice.reducer
